home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / dbf_tc.zip / D_CLOSE.C < prev    next >
Text File  |  1987-06-18  |  1KB  |  48 lines

  1. /* 
  2. **        file:        d_close.c
  3. **        purpose:    routine to close a dbaseiii file after access by the other routines
  4. **                    in dbf.lib.    updates header and places eof marker at end of file.
  5. **        usage:    d = (struct DBF *)malloc(sizeof(struct DBF));
  6. **                    strcpy(d->filename,"filename.dbf");
  7. **                    d_open(d);
  8. **                    ... access file with other routines ...
  9. **                    d_close(d);
  10. **                    free(d);
  11. **        notes:    compile with "tcc -c d_close".    include this file in dbf.lib
  12. **                    see dbf.h for structure of DBF.    ALWAYS close a file that has
  13. **                    been opened, otherwise records may be lost.
  14. **        author:    Mark Sadler
  15. **        revised:    6/18/87
  16. */         
  17. #include <dos.h>
  18. #include <stdio.h>
  19. #include "dbf.h"
  20.  
  21. int d_close(struct DBF *d)
  22. {
  23.     union REGS inregs,outregs;
  24.     if(d->status == updated)
  25.     {
  26.         /* update date data */
  27.         inregs.h.ah=0x2a;
  28.         intdos(&inregs,&outregs);
  29.         d->update_day=outregs.h.dl;
  30.         d->update_mo=outregs.h.dh;
  31.         d->update_yr=outregs.x.cx-1900;
  32.  
  33.         /* position at start of file */
  34.         rewind(d->file_ptr);
  35.         /* rewrite header */
  36.         fwrite(&d->dbf_version,1,12,d->file_ptr);
  37.  
  38.         /* position at end of file     */
  39.         fseek(d->file_ptr,0L,2);
  40.         /* write eof */
  41.         fwrite("\x1a",1,1,d->file_ptr);
  42.     }
  43.     /* free fields array and record */
  44.     free(d->fields_ptr);
  45.     free(d->record_ptr);
  46.     fclose(d->file_ptr);
  47. }
  48.